/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bef.dtgenerator.core;

import com.inspur.edp.bef.bizentity.GspBusinessEntity;
import com.inspur.edp.bef.dtgenerator.BEGeneratorContext;
import com.inspur.edp.bef.dtgenerator.core.rtgen.managergen.BefManagerGenContext;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.cef.generator.coreGenerator.entityGenerator.CommonModelCoreGeneratorContext;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BefCoreGenCtx extends CommonModelCoreGeneratorContext {
  private String privateParentNamespace;
  private String privateParentAssemblyName;
  private java.util.HashMap<String, MediateType> privateBEActionAssFactoryImplTypes;
  private MediateType privateMgrActionAssFactoryImplType;
  private java.util.HashMap<String, MediateType> codeRuleType;
  private java.util.HashMap<String, MediateType> uqConstraintType;
  private MediateType privateUQConstraintInfoType;

  public BefCoreGenCtx(BEGeneratorContext beGenCtx) {
    super(beGenCtx, beGenCtx.getBE());
    privateBEActionAssFactoryImplTypes = new java.util.HashMap<String, MediateType>();
  }

  public BEGeneratorContext getBeGenCtx() {
    return (BEGeneratorContext) super.getCmGenCtx();
  }

  public GspBusinessEntity getBE() {
    return getBeGenCtx().getBE();
  }

  public final String getParentNamespace() {
    return privateParentNamespace;
  }

  public final void setParentNamespace(String value) {
    privateParentNamespace = value;
  }

  public final String getParentAssemblyName() {
    return privateParentAssemblyName;
  }

  public final void setParentAssemblyName(String value) {
    privateParentAssemblyName = value;
  }

  //  public java.lang.Class getCustomActionType(String mdId, String assemblyName, String className)
  // {
  //    return getBeGenCtx().getCustomActionType(mdId, assemblyName, className);
  //  }

  public final java.util.HashMap<String, MediateType> getBEActionAssFactoryImplTypes() {
    return privateBEActionAssFactoryImplTypes;
  }

  public final MediateType getMgrActionAssFactoryImplType() {
    return privateMgrActionAssFactoryImplType;
  }

  public final void setMgrActionAssFactoryImplType(MediateType value) {
    privateMgrActionAssFactoryImplType = value;
  }

  public final java.util.HashMap<String, MediateType> getCodeRuleImpType() {
    if (codeRuleType == null) {
      codeRuleType = new java.util.HashMap<String, MediateType>();
    }
    return codeRuleType;
  }

  public final java.util.HashMap<String, MediateType> getUQConstraintType() {
    if (uqConstraintType == null) {
      uqConstraintType = new java.util.HashMap<String, MediateType>();
    }
    return uqConstraintType;
  }

  public final MediateType getUQConstraintInfoType() {
    return privateUQConstraintInfoType;
  }

  public final void setUQConstraintInfoType(MediateType value) {
    privateUQConstraintInfoType = value;
  }

  private List<MediateType> beforeQueryMediateTypes=new ArrayList<>();

  public List<MediateType> getBeforeQueryMediateTypes() {
    return beforeQueryMediateTypes;
  }
  private List<MediateType> beforeRetrieveMediateTypes=new ArrayList<>();

  public List<MediateType> getBeforeRetrieveMediateTypes() {
    return beforeRetrieveMediateTypes;
  }

  private BefManagerGenContext befManagerGenContext;

  public BefManagerGenContext getBefManagerGenContext() {
    return befManagerGenContext;
  }

  public void setBefManagerGenContext(
      BefManagerGenContext befManagerGenContext) {
    this.befManagerGenContext = befManagerGenContext;
  }

  private  MediateType lcpTypeInfo;

  public MediateType getLcpTypeInfo() {
    return lcpTypeInfo;
  }

  public void setLcpTypeInfo(MediateType lcpTypeInfo) {
    this.lcpTypeInfo = lcpTypeInfo;
  }

  private Map<String,List<MediateType>> afterLoadingDtmTypes=new HashMap<>();


  public Map<String, List<MediateType>> getAfterLoadingDtmTypes() {
    return afterLoadingDtmTypes;
  }

  public void addAfterLoadingDtmTypes(String nodeCode,MediateType mediateType)
  {
    if(afterLoadingDtmTypes.containsKey(nodeCode))
      afterLoadingDtmTypes.get(nodeCode).add(mediateType);
    else
    {
      List<MediateType> types =new ArrayList<>();
      types.add(mediateType);
      afterLoadingDtmTypes.put(nodeCode,types);
    }
  }

  private  List<MediateType> rootAfterQueryDtmTypes=new ArrayList<>();

  public List<MediateType> getRootAfterQueryDtmTypes() {
    return rootAfterQueryDtmTypes;
  }
  private Map<String,List<MediateType>> afterSaveDtmTypes=new HashMap<>();

  public Map<String, List<MediateType>> getAfterSaveDtmTypes() {
    return afterSaveDtmTypes;
  }
  private Map<String,List<MediateType>> onCancelDtmTypes=new HashMap<>();

  public Map<String, List<MediateType>> getOnCancelDtmTypes() {
    return onCancelDtmTypes;
  }

  public void addOnCancelDtmTypes(String nodeCode,MediateType mediateType) {
    if(onCancelDtmTypes.containsKey(nodeCode))
      onCancelDtmTypes.get(nodeCode).add(mediateType);
    else
      {
        List<MediateType> list =new ArrayList<>();
        list.add(mediateType);
        onCancelDtmTypes.put(nodeCode,list);
      }
  }

  @Override
  public String getVersionControlPropertyName() {
    String id = ((GspBusinessEntity)super.getCommonModel()).getVersionContronInfo().getVersionControlElementId();
    if(StringUtils.isEmpty(id)){
      return null;
    }
    return super.getCommonModel().findElementById(id).getLabelID();
  }
}
